<template>
  <div class="listening-learning">
    <!-- 页面头部 -->
    <div class="page-header">
      <button class="back-btn" @click="goBack">
        ← 返回
      </button>
      <h1>👂 磨耳朵听力</h1>
    </div>

    <!-- 标签页导航 -->
    <div class="tabs-nav">
      <button
        :class="['tab-btn', { active: currentTab === 'player' }]"
        @click="currentTab = 'player'"
      >
        🎵 播放
      </button>
      <button
        :class="['tab-btn', { active: currentTab === 'library' }]"
        @click="currentTab = 'library'"
      >
        📚 音频库
      </button>
      <button
        :class="['tab-btn', { active: currentTab === 'settings' }]"
        @click="currentTab = 'settings'"
      >
        ⚙️ 设置
      </button>
    </div>

    <!-- 主播放界面 -->
    <div v-if="currentTab === 'player'" class="player-container">
      <div class="player-card">
        <!-- 封面图区域 -->
        <div class="cover-section">
          <div class="cover-image" :style="{ backgroundImage: `url(${currentAudio.cover || defaultCover})` }">
            <div v-if="!currentAudio.cover" class="cover-placeholder">
              <div class="cover-icon">🎵</div>
            </div>
            <!-- 播放状态动画 -->
            <div v-if="isPlaying" class="play-animation">
              <div class="wave wave1"></div>
              <div class="wave wave2"></div>
              <div class="wave wave3"></div>
            </div>
          </div>
        </div>

        <!-- 音频信息 -->
        <div class="audio-info">
          <h2 class="audio-title">{{ currentAudio.title || '请选择音频' }}</h2>
          <p class="audio-category">{{ getCategoryName(currentAudio.category) }}</p>
          <div class="difficulty-badge" :class="`difficulty-${currentAudio.difficulty || 'easy'}`">
            {{ getDifficultyText(currentAudio.difficulty) }}
          </div>
        </div>

        <!-- 播放控制 -->
        <div class="player-controls">
          <!-- 大型播放/暂停按钮 -->
          <button class="play-pause-btn" @click="togglePlay">
            <span v-if="isPlaying">⏸</span>
            <span v-else>▶</span>
          </button>

          <!-- 进度条 -->
          <div class="progress-section">
            <div class="progress-bar-container" @click="seekTo">
              <div class="progress-bar-bg"></div>
              <div class="progress-bar-fill" :style="{ width: progressPercent + '%' }"></div>
              <div class="progress-bar-handle" :style="{ left: progressPercent + '%' }"></div>
            </div>
            <div class="time-info">
              <span class="current-time">{{ formatTime(currentTime) }}</span>
              <span class="total-time">{{ formatTime(currentAudio.duration || 0) }}</span>
            </div>
          </div>

          <!-- 上一首/下一首按钮 -->
          <div class="nav-buttons">
            <button class="nav-btn" @click="playPrevious" :disabled="!hasPrevious">
              ⏮
            </button>
            <button class="nav-btn" @click="playNext" :disabled="!hasNext">
              ⏭
            </button>
          </div>
        </div>

        <!-- 隐藏的音频元素 -->
        <audio
          ref="audioPlayer"
          :src="currentAudio.url"
          @timeupdate="updateProgress"
          @ended="handleAudioEnded"
          @loadedmetadata="handleLoadedMetadata"
        ></audio>
      </div>
    </div>

    <!-- 音频库界面 -->
    <div v-if="currentTab === 'library'" class="library-container">
      <div class="library-card">
        <!-- 分类筛选 -->
        <div class="category-filters">
          <button
            v-for="category in categories"
            :key="category.value"
            :class="['category-btn', { active: selectedCategory === category.value }]"
            @click="selectedCategory = category.value"
          >
            {{ category.icon }} {{ category.label }}
          </button>
        </div>

        <!-- 音频列表 -->
        <div class="audio-list">
          <div
            v-for="audio in filteredAudios"
            :key="audio.id"
            :class="['audio-item', { active: currentAudio.id === audio.id, playing: isPlaying && currentAudio.id === audio.id }]"
            @click="selectAudio(audio)"
          >
            <div class="audio-item-cover">
              <div class="cover-mini" :style="{ backgroundImage: `url(${audio.cover || defaultCover})` }">
                <div v-if="!audio.cover" class="cover-icon-mini">🎵</div>
              </div>
              <div v-if="isPlaying && currentAudio.id === audio.id" class="playing-indicator">
                <div class="sound-wave">
                  <span></span>
                  <span></span>
                  <span></span>
                </div>
              </div>
            </div>
            <div class="audio-item-info">
              <h3 class="audio-item-title">{{ audio.title }}</h3>
              <div class="audio-item-meta">
                <span class="audio-duration">{{ formatTime(audio.duration) }}</span>
                <span class="audio-difficulty" :class="`difficulty-${audio.difficulty}`">
                  {{ getDifficultyText(audio.difficulty) }}
                </span>
              </div>
            </div>
            <button class="play-item-btn" @click.stop="selectAudio(audio)">
              {{ currentAudio.id === audio.id && isPlaying ? '⏸' : '▶' }}
            </button>
          </div>
        </div>
      </div>
    </div>

    <!-- 设置界面 -->
    <div v-if="currentTab === 'settings'" class="settings-container">
      <div class="settings-card">
        <!-- 定时关闭 -->
        <div class="setting-section">
          <div class="setting-header">
            <div class="setting-icon">⏰</div>
            <h3>定时关闭</h3>
          </div>
          <div class="setting-content">
            <div class="timer-options">
              <button
                v-for="option in timerOptions"
                :key="option.value"
                :class="['timer-btn', { active: timerMinutes === option.value }]"
                @click="setTimer(option.value)"
              >
                {{ option.label }}
              </button>
            </div>
            <div v-if="timerMinutes > 0" class="timer-status">
              <span>⏰ 将在 {{ timerMinutes }} 分钟后自动关闭</span>
              <button class="cancel-timer-btn" @click="cancelTimer">取消</button>
            </div>
          </div>
        </div>

        <!-- 循环模式 -->
        <div class="setting-section">
          <div class="setting-header">
            <div class="setting-icon">🔁</div>
            <h3>循环模式</h3>
          </div>
          <div class="setting-content">
            <div class="loop-options">
              <button
                :class="['loop-btn', { active: loopMode === 'none' }]"
                @click="loopMode = 'none'"
              >
                <span class="loop-icon">⏭</span>
                <span class="loop-label">顺序播放</span>
              </button>
              <button
                :class="['loop-btn', { active: loopMode === 'list' }]"
                @click="loopMode = 'list'"
              >
                <span class="loop-icon">🔁</span>
                <span class="loop-label">列表循环</span>
              </button>
              <button
                :class="['loop-btn', { active: loopMode === 'single' }]"
                @click="loopMode = 'single'"
              >
                <span class="loop-icon">🔂</span>
                <span class="loop-label">单曲循环</span>
              </button>
            </div>
          </div>
        </div>

        <!-- 播放列表管理 -->
        <div class="setting-section">
          <div class="setting-header">
            <div class="setting-icon">📋</div>
            <h3>播放列表</h3>
          </div>
          <div class="setting-content">
            <div class="playlist-controls">
              <button class="control-btn" @click="selectAllAudios">
                {{ allSelected ? '取消全选' : '全选' }}
              </button>
              <button class="control-btn" @click="clearPlaylist">清空列表</button>
            </div>
            <div class="playlist-list">
              <div
                v-for="audio in allAudios"
                :key="audio.id"
                class="playlist-item"
              >
                <label class="playlist-checkbox">
                  <input
                    type="checkbox"
                    :checked="isInPlaylist(audio.id)"
                    @change="togglePlaylistItem(audio.id)"
                  />
                  <span class="checkbox-custom"></span>
                </label>
                <div class="playlist-item-info">
                  <span class="playlist-item-title">{{ audio.title }}</span>
                  <span class="playlist-item-meta">{{ formatTime(audio.duration) }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ListeningLearning',
  data() {
    return {
      currentTab: 'player',
      isPlaying: false,
      currentTime: 0,
      currentAudio: {
        id: null,
        title: '',
        url: '',
        cover: '',
        category: '',
        difficulty: 'easy',
        duration: 0
      },
      selectedCategory: 'all',
      timerMinutes: 0,
      timerId: null,
      loopMode: 'list', // 'none', 'list', 'single'
      playlist: [], // 播放列表中的音频ID
      defaultCover: '',
      categories: [
        { value: 'all', label: '全部', icon: '📚' },
        { value: 'song', label: '儿歌', icon: '🎵' },
        { value: 'story', label: '故事', icon: '📖' },
        { value: 'rhyme', label: '歌谣', icon: '🎶' }
      ],
      timerOptions: [
        { value: 0, label: '关闭' },
        { value: 5, label: '5分钟' },
        { value: 10, label: '10分钟' },
        { value: 15, label: '15分钟' },
        { value: 30, label: '30分钟' },
        { value: 60, label: '1小时' }
      ],
      allAudios: [
        {
          id: 1,
          title: 'ABC字母歌',
          url: '',
          cover: '',
          category: 'song',
          difficulty: 'easy',
          duration: 120
        },
        {
          id: 2,
          title: '小星星',
          url: '',
          cover: '',
          category: 'song',
          difficulty: 'easy',
          duration: 95
        },
        {
          id: 3,
          title: '三只小猪',
          url: '',
          cover: '',
          category: 'story',
          difficulty: 'medium',
          duration: 300
        },
        {
          id: 4,
          title: '数字歌',
          url: '',
          cover: '',
          category: 'rhyme',
          difficulty: 'easy',
          duration: 85
        },
        {
          id: 5,
          title: '小红帽',
          url: '',
          cover: '',
          category: 'story',
          difficulty: 'medium',
          duration: 450
        },
        {
          id: 6,
          title: '颜色歌',
          url: '',
          cover: '',
          category: 'song',
          difficulty: 'easy',
          duration: 110
        }
      ]
    };
  },
  computed: {
    progressPercent() {
      if (!this.currentAudio.duration) return 0;
      return (this.currentTime / this.currentAudio.duration) * 100;
    },
    filteredAudios() {
      if (this.selectedCategory === 'all') {
        return this.allAudios;
      }
      return this.allAudios.filter(audio => audio.category === this.selectedCategory);
    },
    playlistAudios() {
      return this.allAudios.filter(audio => this.playlist.includes(audio.id));
    },
    currentIndex() {
      if (!this.currentAudio.id) return -1;
      return this.playlistAudios.findIndex(audio => audio.id === this.currentAudio.id);
    },
    hasPrevious() {
      return this.currentIndex > 0 || this.loopMode === 'list';
    },
    hasNext() {
      return this.currentIndex < this.playlistAudios.length - 1 || this.loopMode === 'list';
    },
    allSelected() {
      return this.playlist.length === this.allAudios.length && this.allAudios.length > 0;
    }
  },
  mounted() {
    // 初始化播放列表为全部音频
    this.playlist = this.allAudios.map(audio => audio.id);
    // 默认选择第一首
    if (this.allAudios.length > 0) {
      this.selectAudio(this.allAudios[0]);
    }
  },
  beforeUnmount() {
    this.cancelTimer();
  },
  methods: {
    goBack() {
      this.$router.push('/');
    },
    selectAudio(audio) {
      this.currentAudio = { ...audio };
      this.isPlaying = false;
      this.currentTime = 0;
      this.$nextTick(() => {
        if (this.$refs.audioPlayer) {
          this.$refs.audioPlayer.load();
        }
      });
    },
    togglePlay() {
      if (!this.currentAudio.url) {
        // 如果没有音频URL，提示用户
        alert('请从音频库中选择音频');
        return;
      }
      if (this.isPlaying) {
        this.$refs.audioPlayer.pause();
      } else {
        this.$refs.audioPlayer.play();
      }
      this.isPlaying = !this.isPlaying;
    },
    playPrevious() {
      if (this.playlistAudios.length === 0) return;
      let newIndex;
      if (this.currentIndex <= 0) {
        if (this.loopMode === 'list') {
          newIndex = this.playlistAudios.length - 1;
        } else {
          return;
        }
      } else {
        newIndex = this.currentIndex - 1;
      }
      this.selectAudio(this.playlistAudios[newIndex]);
      if (this.isPlaying) {
        this.$nextTick(() => {
          this.$refs.audioPlayer.play();
        });
      }
    },
    playNext() {
      if (this.playlistAudios.length === 0) return;
      let newIndex;
      if (this.currentIndex >= this.playlistAudios.length - 1) {
        if (this.loopMode === 'list') {
          newIndex = 0;
        } else {
          return;
        }
      } else {
        newIndex = this.currentIndex + 1;
      }
      this.selectAudio(this.playlistAudios[newIndex]);
      if (this.isPlaying) {
        this.$nextTick(() => {
          this.$refs.audioPlayer.play();
        });
      }
    },
    seekTo(event) {
      if (!this.$refs.audioPlayer || !this.currentAudio.duration) return;
      const rect = event.currentTarget.getBoundingClientRect();
      const percent = (event.clientX - rect.left) / rect.width;
      const newTime = percent * this.currentAudio.duration;
      this.$refs.audioPlayer.currentTime = newTime;
      this.currentTime = newTime;
    },
    updateProgress() {
      if (this.$refs.audioPlayer) {
        this.currentTime = this.$refs.audioPlayer.currentTime;
      }
    },
    handleAudioEnded() {
      this.isPlaying = false;
      if (this.loopMode === 'single') {
        // 单曲循环
        this.$refs.audioPlayer.currentTime = 0;
        this.$refs.audioPlayer.play();
        this.isPlaying = true;
      } else {
        // 播放下一首
        this.playNext();
        if (this.isPlaying) {
          this.$nextTick(() => {
            this.$refs.audioPlayer.play();
          });
        }
      }
    },
    handleLoadedMetadata() {
      if (this.$refs.audioPlayer) {
        this.currentAudio.duration = this.$refs.audioPlayer.duration;
      }
    },
    formatTime(seconds) {
      if (!seconds || isNaN(seconds)) return '00:00';
      const mins = Math.floor(seconds / 60);
      const secs = Math.floor(seconds % 60);
      return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
    },
    getCategoryName(category) {
      const cat = this.categories.find(c => c.value === category);
      return cat ? cat.label : '';
    },
    getDifficultyText(difficulty) {
      const map = {
        easy: '简单',
        medium: '中等',
        hard: '困难'
      };
      return map[difficulty] || '简单';
    },
    setTimer(minutes) {
      this.cancelTimer();
      if (minutes === 0) return;
      this.timerMinutes = minutes;
      this.timerId = setTimeout(() => {
        this.stopPlayback();
        alert('定时关闭时间到，已停止播放');
        this.timerMinutes = 0;
      }, minutes * 60 * 1000);
    },
    cancelTimer() {
      if (this.timerId) {
        clearTimeout(this.timerId);
        this.timerId = null;
      }
      this.timerMinutes = 0;
    },
    stopPlayback() {
      if (this.$refs.audioPlayer) {
        this.$refs.audioPlayer.pause();
        this.$refs.audioPlayer.currentTime = 0;
      }
      this.isPlaying = false;
      this.currentTime = 0;
    },
    togglePlaylistItem(audioId) {
      const index = this.playlist.indexOf(audioId);
      if (index > -1) {
        this.playlist.splice(index, 1);
        // 如果当前播放的音频被移除，播放下一首
        if (this.currentAudio.id === audioId) {
          this.playNext();
        }
      } else {
        this.playlist.push(audioId);
      }
    },
    isInPlaylist(audioId) {
      return this.playlist.includes(audioId);
    },
    selectAllAudios() {
      if (this.allSelected) {
        this.playlist = [];
      } else {
        this.playlist = this.allAudios.map(audio => audio.id);
      }
    },
    clearPlaylist() {
      if (confirm('确定要清空播放列表吗？')) {
        this.playlist = [];
        this.stopPlayback();
        this.currentAudio = {
          id: null,
          title: '',
          url: '',
          cover: '',
          category: '',
          difficulty: 'easy',
          duration: 0
        };
      }
    }
  }
};
</script>

<style scoped>
.listening-learning {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

.back-btn {
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  color: white;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 500;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateX(-5px);
}

.page-header h1 {
  margin: 0;
  color: white;
  font-size: 28px;
  font-weight: 600;
}

/* 标签页导航 */
.tabs-nav {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

.tab-btn {
  flex: 1;
  padding: 15px 20px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  color: white;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}

.tab-btn.active {
  background: white;
  color: #667eea;
  border-color: white;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* 播放器容器 */
.player-container {
  max-width: 1200px;
  margin: 0 auto;
}

.player-card {
  background: white;
  border-radius: 24px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.cover-section {
  margin-bottom: 30px;
}

.cover-image {
  width: 100%;
  max-width: 500px;
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 20px;
  background-size: cover;
  background-position: center;
  background-color: #f0f0f0;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.cover-icon {
  font-size: 120px;
  opacity: 0.7;
}

.play-animation {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.wave {
  width: 8px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 4px;
  animation: wave-animation 1.2s ease-in-out infinite;
}

.wave1 {
  height: 20px;
  animation-delay: 0s;
}

.wave2 {
  height: 30px;
  animation-delay: 0.2s;
}

.wave3 {
  height: 20px;
  animation-delay: 0.4s;
}

@keyframes wave-animation {
  0%, 100% {
    transform: scaleY(0.5);
  }
  50% {
    transform: scaleY(1);
  }
}

.audio-info {
  text-align: center;
  margin-bottom: 30px;
}

.audio-title {
  font-size: 32px;
  font-weight: 700;
  color: #2c3e50;
  margin: 0 0 10px 0;
}

.audio-category {
  font-size: 18px;
  color: #7f8c8d;
  margin: 0 0 15px 0;
}

.difficulty-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
}

.difficulty-easy {
  background: #d4edda;
  color: #155724;
}

.difficulty-medium {
  background: #fff3cd;
  color: #856404;
}

.difficulty-hard {
  background: #f8d7da;
  color: #721c24;
}

.player-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 25px;
}

.play-pause-btn {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  color: white;
  font-size: 48px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-pause-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 35px rgba(102, 126, 234, 0.6);
}

.play-pause-btn:active {
  transform: scale(0.95);
}

.progress-section {
  width: 100%;
  max-width: 600px;
}

.progress-bar-container {
  position: relative;
  width: 100%;
  height: 8px;
  background: #e0e0e0;
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 10px;
}

.progress-bar-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #e0e0e0;
  border-radius: 4px;
}

.progress-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  border-radius: 4px;
  transition: width 0.1s linear;
}

.progress-bar-handle {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 18px;
  background: white;
  border: 3px solid #667eea;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.time-info {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: #7f8c8d;
}

.nav-buttons {
  display: flex;
  gap: 20px;
}

.nav-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(102, 126, 234, 0.1);
  border: 2px solid rgba(102, 126, 234, 0.3);
  color: #667eea;
  font-size: 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn:hover:not(:disabled) {
  background: rgba(102, 126, 234, 0.2);
  transform: scale(1.1);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* 音频库样式 */
.library-container {
  max-width: 1200px;
  margin: 0 auto;
}

.library-card {
  background: white;
  border-radius: 24px;
  padding: 30px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.category-filters {
  display: flex;
  gap: 10px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.category-btn {
  padding: 12px 24px;
  background: #f8f9fa;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: #5d6d7e;
  cursor: pointer;
  transition: all 0.3s ease;
}

.category-btn:hover {
  background: #e9ecef;
  border-color: #667eea;
}

.category-btn.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: transparent;
}

.audio-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.audio-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px;
  background: #f8f9fa;
  border: 2px solid transparent;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.audio-item:hover {
  background: #e9ecef;
  border-color: #667eea;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.audio-item.active {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
  border-color: #667eea;
}

.audio-item-cover {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

.cover-mini {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-color: #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover-icon-mini {
  font-size: 40px;
  opacity: 0.5;
}

.playing-indicator {
  position: absolute;
  bottom: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  background: rgba(102, 126, 234, 0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sound-wave {
  display: flex;
  gap: 2px;
  align-items: center;
}

.sound-wave span {
  width: 3px;
  background: white;
  border-radius: 2px;
  animation: sound-wave-animation 1s ease-in-out infinite;
}

.sound-wave span:nth-child(1) {
  height: 8px;
  animation-delay: 0s;
}

.sound-wave span:nth-child(2) {
  height: 12px;
  animation-delay: 0.2s;
}

.sound-wave span:nth-child(3) {
  height: 8px;
  animation-delay: 0.4s;
}

@keyframes sound-wave-animation {
  0%, 100% {
    transform: scaleY(0.5);
  }
  50% {
    transform: scaleY(1);
  }
}

.audio-item-info {
  flex: 1;
  min-width: 0;
}

.audio-item-title {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 8px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audio-item-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 14px;
  color: #7f8c8d;
}

.audio-difficulty {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}

.play-item-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-item-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* 设置界面样式 */
.settings-container {
  max-width: 1200px;
  margin: 0 auto;
}

.settings-card {
  background: white;
  border-radius: 24px;
  padding: 30px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.setting-section {
  margin-bottom: 40px;
}

.setting-section:last-child {
  margin-bottom: 0;
}

.setting-header {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.setting-icon {
  font-size: 32px;
}

.setting-header h3 {
  margin: 0;
  font-size: 24px;
  color: #2c3e50;
  font-weight: 600;
}

.setting-content {
  padding-left: 50px;
}

.timer-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 15px;
}

.timer-btn {
  padding: 12px 24px;
  background: #f8f9fa;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: #5d6d7e;
  cursor: pointer;
  transition: all 0.3s ease;
}

.timer-btn:hover {
  background: #e9ecef;
  border-color: #667eea;
}

.timer-btn.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: transparent;
}

.timer-status {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px;
  background: #fff3cd;
  border-radius: 12px;
  color: #856404;
  font-weight: 600;
}

.cancel-timer-btn {
  padding: 6px 16px;
  background: #f8d7da;
  border: none;
  border-radius: 8px;
  color: #721c24;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.cancel-timer-btn:hover {
  background: #f5c6cb;
}

.loop-options {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

.loop-btn {
  flex: 1;
  min-width: 150px;
  padding: 20px;
  background: #f8f9fa;
  border: 2px solid #e0e0e0;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.loop-btn:hover {
  background: #e9ecef;
  border-color: #667eea;
  transform: translateY(-2px);
}

.loop-btn.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: transparent;
}

.loop-icon {
  font-size: 32px;
}

.loop-label {
  font-size: 16px;
  font-weight: 600;
}

.playlist-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.control-btn {
  padding: 10px 20px;
  background: #f8f9fa;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #5d6d7e;
  cursor: pointer;
  transition: all 0.3s ease;
}

.control-btn:hover {
  background: #e9ecef;
  border-color: #667eea;
}

.playlist-list {
  max-height: 400px;
  overflow-y: auto;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 10px;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 12px;
  border-radius: 10px;
  transition: all 0.3s ease;
}

.playlist-item:hover {
  background: #f8f9fa;
}

.playlist-checkbox {
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.playlist-checkbox input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.checkbox-custom {
  width: 24px;
  height: 24px;
  border: 2px solid #667eea;
  border-radius: 6px;
  background: white;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.playlist-checkbox input[type="checkbox"]:checked + .checkbox-custom {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-color: transparent;
}

.playlist-checkbox input[type="checkbox"]:checked + .checkbox-custom::after {
  content: '✓';
  color: white;
  font-size: 16px;
  font-weight: bold;
}

.playlist-item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.playlist-item-title {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
}

.playlist-item-meta {
  font-size: 14px;
  color: #7f8c8d;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .player-card,
  .library-card,
  .settings-card {
    padding: 20px;
  }

  .audio-title {
    font-size: 24px;
  }

  .play-pause-btn {
    width: 80px;
    height: 80px;
    font-size: 40px;
  }

  .audio-list {
    grid-template-columns: 1fr;
  }

  .loop-options {
    flex-direction: column;
  }

  .loop-btn {
    min-width: 100%;
  }
}
</style>
